package studychinese.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.activity.BaseActivity;
import com.hschinese.pronunciation.bean.TestChinesePraciticeBean;
import com.hschinese.pronunciation.utils.NumberFormatUtil;
import com.hschinese.pronunciation.widget.LineGridView;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import studychinese.adapters.GvResultchinaAdapter;
import studychinese.model.UserBean;

public class ChinaReportActivity extends BaseActivity {

    @Bind(R.id.left_img)
    ImageView leftImg;
    @Bind(R.id.center_img_china)
    ImageView centerImgChina;
    @Bind(R.id.right_img_china)
    ImageView rightImgChina;
    @Bind(R.id.right_tv_china)
    TextView rightTvChina;
    @Bind(R.id.rl_title_china)
    RelativeLayout rlTitleChina;
    @Bind(R.id.tv_head_resultpinyin)
    TextView tvHeadResultpinyin;
    @Bind(R.id.rl_headresult_pinyin)
    RelativeLayout rlHeadresultPinyin;
    @Bind(R.id.lv_result_pinyin)
    LineGridView lvResultPinyin;
    @Bind(R.id.iv_wrong_pinyin)
    ImageView ivWrongPinyin;
    @Bind(R.id.fl_native_whystuday_cz)
    TagFlowLayout flNativeWhystudayCz;
    private int rightTimes;
    private TagAdapter<String> mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result_china);
        ButterKnife.bind(this);
        centerImgChina.setImageResource(R.mipmap.xuexibaogao);
        rightImgChina.setImageResource(R.mipmap.ic_share);
        lvResultPinyin.setFocusable(false);
        TestChinesePraciticeBean tetResultInfor = UserBean.getChinesePraciceInfor();
        List<TestChinesePraciticeBean.DataBean> data = tetResultInfor.getData();
        if (tetResultInfor.getTotalcount() != tetResultInfor.getState()+1) {
            data.clear();
            tvHeadResultpinyin.setText("0%");
        }else {
            for (int i = 0; i <data.size() ; i++) {
                if(data.get(i).isRight()){
                    rightTimes++;
                }
            }
            String percent = NumberFormatUtil.getPercent(rightTimes-1, data.size());
            tvHeadResultpinyin.setText(percent+"%");
        }
        GvResultchinaAdapter gvResultPinyinAdapter = new GvResultchinaAdapter(data, this);
        lvResultPinyin.setAdapter(gvResultPinyinAdapter);
        lvResultPinyin.setOverScrollMode(View.OVER_SCROLL_NEVER);

        setView();
    }

    @OnClick({R.id.left_img, R.id.right_img_china})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_img:
                this.finish();
                break;
            case R.id.right_img_china:
                break;
        }
    }
    private void setView() {
        List<String> listWrongChain = UserBean.getListWrongChain();
        flNativeWhystudayCz.setAdapter(mAdapter = new TagAdapter<String>(listWrongChain) {

            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) getLayoutInflater().inflate(R.layout.tv_result_pinyin,
                        flNativeWhystudayCz, false);

                tv.setText(s);
                return tv;
            }
        });
        mAdapter.setSelectedList();
        //获得所有选中的pos集合
        flNativeWhystudayCz.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                //Toast.makeText(getActivity(), mVals[position], Toast.LENGTH_SHORT).show();
                //view.setVisibility(View.GONE);
                return true;
            }
        });


    }
}
